<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec'
	uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
            	<sec:authorize url='/warehouse_add.do'>
                <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                </sec:authorize>
                <sec:authorize url='/warehouse_edit.do'>
                <a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>
                </sec:authorize>
                <sec:authorize url='/warehouse_delete.do'>
                <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>      
                </sec:authorize> 
            </td>
            <td style="white-space:nowrap;">
	           	 <span>仓库名称：</span>
	             <input id="name" class="mini-textbox" emptyText="请输入仓库名称" style="width:100px;" onenter="onKeyEnter"/>   
	             <span>编号：</span>
	             <input id="code" class="mini-textbox" emptyText="请输入编号" style="width:100px;" onenter="onKeyEnter"/>   
	         </td>
	         <td style="white-space:nowrap;">
                <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
              </td>
        </tr>
    </table>           
</div>
<div class="mini-fit" >
<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20" multiSelect="true"
	url="warehouse_page.do"
	style="width:100%;height:100%;">
	<div property="columns">
		<div type="indexcolumn"></div>
		<div type="checkcolumn"></div>
		<div field="name" width="200" headerAlign="center" align="center">仓库名称</div>
		<div field="address" width="200" headerAlign="center" align="center">地址</div>
		<div field="code" width="100" headerAlign="center" align="center">编号</div>
		<div field="area" width="100" headerAlign="center" allowSort="true" align="center">面积大小（㎡）</div>
	</div>
</div>
</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();

function search() {
    var name = mini.get("name").getValue();
    var code = mini.get("code").getValue();
    grid.load({ 
    	name: name,
    	code: code,
    });
}

//添加
function add() {
    mini.open({
        url: "warehouse_add.do",
        allowResize:false,
        title: "新增仓库信息", width: 600, height: 230,
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "保存成功！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
	            grid.reload();
        	}
        }
    });
}

//修改
function edit() {
    var row = grid.getSelecteds();
    if (row.length == 1) {
        mini.open({
            url: "warehouse_edit.do",
            allowResize:false,
            title: "编辑仓库信息", width: 600, height: 230,
            onload: function () {
                var iframe = this.getIFrameEl();
                iframe.contentWindow.SetData(row[0]);
            },
            ondestroy: function (action) {
            	if(action == 'succ'){
            		mini.showMessageBox({
                        title: "提示",
                        showModal:false,
                        iconCls: "mini-messagebox-info",
                        message: "修改成功！",
                        timeout: 3000,
                        x: 'right',
                        y: 'bottom'
                    });
                	grid.reload();
            	}
            }
        });
        
    } else {
    	mini.alert("请选中一条记录");
    }
    
}

//删除
function remove() {
	var rows = grid.getSelecteds();
	if (rows.length > 0) {
    	mini.confirm("确定删除选中记录？", "删除",
               function (action) {
                   if (action == "ok") {
                	   var arr = new Array();
	               		$.each(rows,function(i,v){
	               			arr.push(v.id);
	               		});
	               		var rids = arr.join("-");
	                    $.post("warehouse_delete.do",{id:rids},function(data){
	                    	if(data.success){
	                    		mini.showMessageBox({
	                                title: "提示",
	                                showModal:false,
	                                iconCls: "mini-messagebox-info",
	                                message: "已删除！",
	                                timeout: 3000,
	                                x: 'right',
	                                y: 'bottom'
	                            });
	                    		grid.reload();
	                    	}else{
	                    		mini.alert("该仓库下有药品，请清空所有药品后重试！","提醒");
	                    	}
	                    },"json");
                   }
               });
        
    } else {
        alert("请选中一条记录");
    }
}
</script>
</body>
</html>